/***********************************************************
*discription    label标签示例
*author         david
*date           2021-5-12
*modify         2021-5-12 8：30
************************************************************/
#include "mainWindow.h"

mainWindow::mainWindow()
{
	//QRect screenRect = QApplication::desktop()->screenGeometry();
	//this.setGeometry(100, 100, 800, 400);

    label1 = new QLabel("普通label");
    //加载动态图片
    label2 = new QLabel("label2");
    QMovie *movie = new QMovie(":images/fire.gif");
    label2->setMovie(movie);
    //启动
    movie->start();

    lcdNum = new QLCDNumber(this);
    //策略
    QSizePolicy sizePolicy = this->sizePolicy();
    sizePolicy.setHorizontalPolicy(QSizePolicy::Expanding);
    sizePolicy.setVerticalPolicy(QSizePolicy::Expanding);
    lcdNum->setSizePolicy(sizePolicy);
    lcdNum->resize(100,50);
    // 设置能显示的位数
    lcdNum->setDigitCount(25);
    // 设置显示的模式为十进制
    lcdNum->setMode(QLCDNumber::Dec);
    // 设置显示外观
    lcdNum->setSegmentStyle(QLCDNumber::Flat);
    // 设置样式
    lcdNum->setStyleSheet("border: 1px solid green; color: green; background: silver;");

    QTimer *timer = new QTimer(this);
    // 设置定时间隔
    timer->setInterval(1000);
    connect(timer, SIGNAL(timeout()), this, SLOT(onTimeOut()));
    // 启动定时器
    timer->start();

    //tab标签
    QTabWidget *tab = new QTabWidget();
	//布局
	QVBoxLayout *vLay = new QVBoxLayout();
	QHBoxLayout *hLay = new QHBoxLayout();
    textEdit = new QTextEdit("textEdit");
    vLay->addWidget(label1);
    vLay->addWidget(label2);
    vLay->addWidget(lcdNum);
    //tab1
    QWidget *pWidget = new QWidget(this);
    pWidget->setLayout(vLay);
    //tab2
    QWidget *widget2 = new QWidget();
    widget2->setLayout(hLay);
    //增加tab
    tab->addTab(pWidget, "v"); //添加widget，以及给它起名
    tab->addTab(widget2, "h");
    setCentralWidget(tab);
}

void mainWindow::onTimeOut()
{
    // 获取系统当前时间
    QDateTime dateTime = QDateTime::currentDateTime();
    // 显示的内容
    lcdNum->display(dateTime.toString("yyyy-MM-dd HH:mm:ss.zzz"));
}
